package pro.cherish.smartfile.rest;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import pro.cherish.smartfile.common.module.PageVo;
import pro.cherish.smartfile.common.response.Result;
import pro.cherish.smartfile.module.entity.Attachment;
import pro.cherish.smartfile.service.AttachmentService;
import reactor.core.publisher.Mono;

/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-12-06 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：CenterController
 * @Description 功能说明：
 * <p>
 *
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-12-06 lys
 */
@RestController
@RequestMapping("/api/v1/center")
@Api(tags = "管理中心")
@Slf4j
public class CenterController {
    @Autowired
    private AttachmentService attachmentService;

    @ApiOperation("获取某个人的所有上传记录")
    @GetMapping("uploads")
    public Mono<Result<PageVo<Attachment>>> uploads(@ApiParam("页码") @RequestParam(value = "pageNum", defaultValue = "1") long pageNo,
                                                    @ApiParam("每页数量") @RequestParam(value = "pageSize", defaultValue = "20") long pageSize, String userId) {
        Page<Attachment> page = new Page<>(pageNo, pageSize);
        IPage<Attachment> attachmentPage = attachmentService.queryMyUploads(page, userId);
        PageVo<Attachment> pageVo = new PageVo<>();
        BeanUtil.copyProperties(attachmentPage, pageVo);
        pageVo.setPages(attachmentPage.getPages());
        return Mono.just(Result.ok(pageVo));
    }
}
